function New-AzureSQLDatabase {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $true)][string]$ResourceGroup,
        [Parameter(Mandatory = $true)][string]$ServerName,
        [Parameter(Mandatory = $true)][string]$DatabaseName,
        [Parameter(Mandatory = $true)][pscredential]$LSInsightCredential,
        [Parameter(Mandatory = $true)][string]$PricingTier,
        [Parameter(Mandatory = $true)][string]$SASToken,
        [Parameter(Mandatory = $true)][string]$BacPacFile
    )

    # Import database parameters.
    $params = @{
        ResourceGroupName = $ResourceGroup
        ServerName = $ServerName
        DatabaseName = $DatabaseName
        AdministratorLogin = $LSInsightCredential.UserName
        AdministratorLoginPassword = $LSInsightCredential.Password
        Edition = 'Standard'
        ServiceObjectiveName = $PricingTier
        DatabaseMaxSizeBytes = 250GB
        StorageKeyType = 'SharedAccessKey'
        StorageKey = $SASToken
        StorageUri = $BacPacFile
        AuthenticationType = 'Sql'
    }

    # Start the database import.
    $ImportRequest = New-AzSqlDatabaseImport @params

    # Check the time.
    $startTime = Get-Date

    # Wait for the import to finish. (Or just continue after x minues).
    do
    {
        # Get status of the database import.
        $ImportStatus = Get-AzSqlDatabaseImportExportStatus -OperationStatusLink $ImportRequest.OperationStatusLink

        # Display the correct progress bar message.
        if ($ImportStatus.StatusMessage -like '* 1 *') {
            # 1% (Queued).
            Write-ProgressBarQueued -Repetitions 6 -MaxDots 4
        }
        elseif ($ImportStatus.StatusMessage -like 'Running*') {
            # More than 1%.
            $Percentage = Get-FirstNumber $ImportStatus.StatusMessage
            Write-ProgressBarImporting -Percentage $([int]$Percentage) -Repetitions 2 -MaxDots 4
        }
        elseif ($ImportStatus.StatusMessage -eq 'Completed') {
            # Completed.
            Write-Progress -Activity 'Database import completed' -Status "100% Complete:" -PercentComplete 100; Start-Sleep -Seconds 5
        }
        else {
            # Unknown status message.
            Write-ProgressBarUnexpected $ImportStatus.StatusMessage -Repetitions 6 -MaxDots 4
        }

        # Check if the script should wait any longer.
        $splitTime = Get-Date
        $duration = NEW-TIMESPAN -Start $startTime -End $splitTime
        $timeout = $duration.TotalMinutes -ge 15
        if ($timeout) {
            Write-Warning "The database import is taking longer than usual. The script will continue but you will have to monitor the Azure Portal to see if the Azure SQL database resource has been imported."
            break
        }

    } while ($ImportStatus.StatusMessage -ne 'Completed')

    return
}